package bug;

import bug.BaseMain;
import bug.persistent.Category;
import bug.persistent.Project;
import bug.persistent.User;
import bug.persistent.UserProject;

import java.util.List;

/**
 * User: ion
 * Date: Aug 30, 2008 - 10:54:08 AM
 */

public class Main2 extends BaseMain {

    public static void main(String[] args) {
        new Main2().run();
    }

    public void run() {
        Category c = new Category();
        c.setName("Nine.");

//        Session s = ((ProjectDaoHibernate)projectDao).getSessionFactory().openSession();

        beginSession();

        List<User> users = userDao.getAll();
        for (User user: users) {
            System.out.println(String.format("User [%s] works on [%d] projects.", user.getLoginName(), user.getUserProjects().size()));
            for (UserProject up : user.getUserProjects()) {
                System.out.println("\t" + up.getProject().getName());
            }
        }
        endSession();

        beginSession();
        User u = userDao.getById(1);
        System.out.println(u.getUserProjects().get(0).getProject().getName());
        System.out.println(u.getUserProjects().get(1).getProject().getName());
    }
}